﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SiteParser.Core.Logging;

namespace SiteParser.Core.ParserEntities
{
	public class ListHtmlParser : ParserEntity
	{
		public int StartIndex { get; set; }
		public int MaximumIterationCount { get; set; }

		protected override void ProcessCurrentContext(ParsingContext context, IHtmlIterator htmlIterator) {
			Logger.Info("Processing current context for 'ListHtmlParser'");

			htmlIterator.MoveNext();
			var contextObject = context.InnerEntity;
			var list = InitializeProperty(contextObject, PropertyName);

			ParsingContext childContext = new ParsingContext()
			{
				InnerEntity = list,
				InnerHtml = htmlIterator.SelectedValue,
				CurrentUrl = context.CurrentUrl,
				ParentContext = context
			};

			var listTemplateParser = (ParserEntity)ChildEntities[0];
			listTemplateParser.Parse(childContext);
		}
	}
}
